package com.boyunv.visitor.example01;
/*
 *@description
 *
 *@author boyunv
 *@create 2023/9/3 9:37
 *@version 1.0
 */

import java.text.NumberFormat;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;

public class Client {
    public static void main(String[] args) {
        LocalDate billDate = LocalDate.now();
        
        Candy candy = new Candy("徐福记",LocalDate.of(2022,10,1),10.0);
        System.out.println("糖果: " + candy.getName());
        
        double rate = 0.0;
        
        long days = billDate.toEpochDay() - candy.getProducedDate().toEpochDay();
        System.out.println(days);
        
        if(days > 180){
            System.out.println("超过半年的糖果,请勿食用!");
        }else{
            rate = 0.9;
            double discountPrice = candy.getPrice() * rate;
            System.out.println("打折后的价格"+ NumberFormat.getCurrencyInstance().format(discountPrice));
        }
        
        //三件商品加入购物车  //模拟添加多个商品
        List<Acceptable> products = Arrays.asList(
                new Candy("金丝猴奶糖",LocalDate.of(2022,6,10),10.00),
                new Wine("衡水老白干",LocalDate.of(2020,6,10),100.00),
                new Fruit("草莓",LocalDate.of(2022,10,12),50.00,1)
        );
        
        Visitor visitor = new DiscountVisitor(LocalDate.of(2022,10,17));
        for (Acceptable product : products) {
            product.accept(visitor);
        }
        
    }
}
